package com.platformer.view;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.platformer.model.Hero;

public class HeroRenderer {

	// public static final float WORLDTOBOX = 1/15f;
	// public static final float BOXTOWORLD = 15f;
	public static final float PIXELS_PER_METER = 10;

	private Hero hero;
	private Texture walkSheet;
	private Animation rightWalkingAnimation;
	private TextureRegion[] rightWalkingFrames;
	private TextureRegion currentFrame;
	
	private float stateTime;

	public HeroRenderer(Hero hero) {
		this.hero = hero;
		
		walkSheet = new Texture(Gdx.files.internal("data/dennis0.png"));
		
		rightWalkingFrames = new TextureRegion[9];
//		for(int i = 0, j = 0; i < 9; i++, j += 64) {
//			rightWalkingFrames[i] = new TextureRegion(walkSheet, j, 64*3, 64, 64);
//		}
		rightWalkingFrames[0] = new TextureRegion(walkSheet, 0, 0, 70, 85);
		
		rightWalkingAnimation = new Animation(0.075f, rightWalkingFrames);
		
		stateTime = 0f;
		currentFrame = rightWalkingFrames[0];
	}

	public void render(float delta, SpriteBatch batch, OrthographicCamera camera) {
		stateTime += delta;
		Vector2 position = hero.getPosition();
//		batch.draw(textureRegion, position.x - 1, position.y - 1,
//				1f, 1f,
//				2, 2,
//				1, 1,
//				hero.getAngle());
		
		camera.position.x = position.x;
		
		batch.draw(currentFrame, position.x - 1.55f, position.y - 1.55f,
				1f, 1f,
				3, 3,
				1, 1,
				hero.getAngle());
		
		System.out.println(hero.getState() + " x:" + hero.getWorldVector().x);
	}

}
